﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Private.Master" Inherits="System.Web.Mvc.ViewPage" %>

<%@ Import Namespace="WebHoiChoMuaBan.Controllers.Global" %>
<%@ Import Namespace="WebHoiChoMuaBan.Models" %>
<%@ Import Namespace="WebHoiChoMuaBan.Controllers.Helpers" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContentHolder" runat="server">
    <%
        var hMem = (MemberHelper)ViewData["hMem"];
        var isOwner = (bool)ViewData["IsOwner"];
    %>
    <div class="private_share_post_top">
        <div class="private_sharepost_menu">
            <ul>
                <li><a href="<%=Url.Action("List", "Message", new { uid = hMem.Member.MemId,isEditMode = "False",type=1,page=1 })%>"
                    class="menu_select">Lời nhắn mới nhận</a></li>
                <li><a href="<%=Url.Action("List", "Message", new { uid = hMem.Member.MemId,isEditMode = "False",type=2,page=1 })%>"
                    class="menu_select">Lời nhắn cũ</a></li>
                <li><a href="<%=Url.Action("List", "Message", new { uid = hMem.Member.MemId,isEditMode = "False",type=3,page=1 })%>"
                    class="menu_select">Lời nhắn đã gởi</a></li>
            </ul>
        </div>
        <% if (isOwner)
           { %>
        <div class="private_button_left">
            <div class="private_bt_newspost">
                <a href="#">
                    <img src="/../Content/Images/icon_newpost.gif" />
                    Viết bài mới... </a>
            </div>
        </div>
        <% } %>
    </div>
    <%
        int p;
        try
        {
            p = int.Parse(Request.QueryString["page"] + "");
        }
        catch
        {
            p = 1;
        }
        MemberHelper.CommentMemberResult privateMsg;
        int type = int.Parse(Request.QueryString.Get("type"));
        if (type == 1)//tin mới
        {
            privateMsg = hMem.getNewMessages(p, Config.ITEMS_PER_PAGE);
        }
        else
        {
            if (type == 2)//tin cũ hơn
            {
                privateMsg = hMem.getOlderMessages(p, Config.ITEMS_PER_PAGE);
            }
            else
            {
                privateMsg = hMem.getSendMessages(p, Config.ITEMS_PER_PAGE); 
            }
        }
    %>
    <%--start phân trang--%>
    <div class="private_breakpage">
        <%
                        
      
            if (Request.QueryString["p"] == null && !int.TryParse(Request.QueryString["p"], out p))
            //if(p!=0)
            {
                p = 1;
            }
            else p = int.Parse(Request.QueryString["p"]);
        %>
        <% if (p > 1)
           { %><a href='<%=string.Format("{0}'",
                                                          Url.Action("List", "Message", new { uid = hMem.Member.MemId,isEditMode = "False" ,page=p-1})) %>'><img
                                                              src="/../Content/Images/arrow_breakpage_left.gif" alt="">&nbsp;Trang
               trước</a>
        <% } %>
        <%
            if (p > 3)
                Response.Write(string.Format("<a href='{0}?p={1}'{2}>{3}</a> ",
                                             Url.Action("List", "Message", new { uid = hMem.Member.MemId, isEditMode = "False", page = 1 }),
                                                1,
                                                string.Empty,
                                                 1));
            if (p > 4)
                Response.Write("...");
            int total = privateMsg.totalpages;
            int from = (p - 2 < 1 ? 1 : p - 2);
            int to = (p + 2 >= total ? total : p + 2);
            for (int i = from; i <= to; i++)
                Response.Write(string.Format("<a href='{0}'{2}>{3}</a> ",
                                               Url.Action("List", "Message", new { uid = hMem.Member.MemId, isEditMode = "False", page = i }),
                                                i,
                                                (i == p ? "class='menu_select'" : string.Empty),
                                                 i));
            if (p <= total - 4)
                Response.Write("...");
            if (p <= total - 3)
                Response.Write(string.Format("<a href='{0}'{2}>{3}</a> ",
                                             Url.Action("List", "Message", new { uid = hMem.Member.MemId, isEditMode = "False", page = total }),
                                                total,
                                                string.Empty,
                                                total));
        %>
        <% if (p < privateMsg.totalpages)
           { %><a href='<%=string.Format("{0}'",
                                                             Url.Action("List", "Message", new { uid = hMem.Member.MemId,isEditMode = "False",page=p+1 }),
                                                            p+1) %>'>Trang sau&nbsp;<img src="/../Content/Images/arrow_breakpage_right.gif" alt=""></a>
        <% } %>
    </div>
    <%--end phân trang--%>
    <div class="private_thumb_listpr">
        <%
            foreach (var msg in privateMsg.CommentMembers)
            {
                if (msg.ComIdReply == null)
                {
        %>
        <div class="private_content_mg_thumb">
            <div class="private_img_post_bt">
                <a href="<%=Url.Action("Index", "Home", new { uid = msg.MemberSends.MemId })%>">
                    <img src="/../Content/Images/Upload/<%=msg.MemberSends.MemAvatar %>" alt="" class="private_img_post"
                        width="48" height="48" />
                </a>
            </div>
            <div class="private_messages_text">
                <p>
                    <a href="<%=Url.Action("Index", "Home", new { uid = msg.MemberSends.MemId })%>" class="private_user">
                        <%=(msg.MemberSends.MemId.Equals(Session["MemId"]) ? "Tui" : msg.MemberSends.MemFullname) %>:&nbsp;</a>
                    <%=msg.ComContent%>
                </p>
                <br />
                <div class="private_message_rpbt_delete">
                    <p class="private_timer">
                        <i>(<%=msg.ComDate.ToString("hh:mm dd/MM/yyyy")%>)</i></p>
                    <% if (isOwner)
                       { %>
                    <div class="private_content_rp">
                        <a href="#"><span class="private_button_upload">
                            <img src="/../Content/Images/icon_plus_up.gif">Trả lời</span></a></div>
                    <div class="private_messages_delete">
                        <a href="#">
                            <img src="/../Content/Images/delete_bt.gif" alt="" /></a></div>
                    <% } %>
                </div>
            </div>
        </div>
        <%
            if (msg.CommentReplies != null && msg.CommentReplies.Count > 0)
            {
                foreach (var reply in msg.CommentReplies.AsEnumerable())
                {
        %>
        <div class="private_content_mg_reply_thumb">
            <div class="private_img_post_bt">
                <a href="<%=Url.Action("Index", "Home", new { uid = reply.MemberSends.MemId })%>">
                    <img src="/../Content/Images/Upload/<%=reply.MemberSends.MemAvatar %>" alt="" class="private_img_post"
                        width="48" height="48" />
                </a>
            </div>
            <div class="private_messages_text">
                <p>
                    <a href="<%=Url.Action("Index", "Home", new { uid = reply.MemberSends.MemId })%>"
                        class="private_user">
                        <%=(reply.MemberSends.MemId.Equals(Session["MemId"]) ? "Tui" : reply.MemberSends.MemFullname) %>:&nbsp;</a>
                    <%=reply.ComContent%>
                </p>
                <br />
                <div class="private_message_rpbt_delete">
                    <p class="private_timer">
                        <i>(<%=reply.ComDate.ToString("hh:mm dd/MM/yyyy")%>)</i></p>
                    <div class="private_messages_delete">
                        <a href="#">
                            <img src="/../Content/Images/delete_bt.gif" alt="" /></a></div>
                </div>
            </div>
        </div>
        <%
            }
            }
                }
            } 
        %>
    </div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="TitleHolder" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadHolder" runat="server">
</asp:Content>
